﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CutAways.Geometry;
using Tao.OpenGl;

namespace CutAways.Shaders
{
    class TubeCutShader : ShaderHolder
    {
        public TubeCutShader(string[] vertexShaderFile, string[] fragmentShaderFile, string info)
        {
            base.LoadShaders(vertexShaderFile, fragmentShaderFile, info);
        }

        public bool SetParameters(Vector back, Vector front, Vector reference, Interval[] cuttingParametres)
        {
            if (cuttingParametres.Length != 2)
                return false;

            Gl.glUseProgram(Program);

            int debugColor = Gl.glGetUniformLocation(Program, "debugColor");

            int backId = Gl.glGetUniformLocation(Program, "back");
            int frontId = Gl.glGetUniformLocation(Program, "front");
            int referenceId = Gl.glGetUniformLocation(Program, "reference");

            int minAxis = Gl.glGetUniformLocation(Program, "minAxis");
            int maxAxis = Gl.glGetUniformLocation(Program, "maxAxis");
            int minAngle = Gl.glGetUniformLocation(Program, "minAngle");
            int maxAngle = Gl.glGetUniformLocation(Program, "maxAngle");

            Gl.glUniform4f(debugColor, 0, 0, 1, 1);

            Gl.glUniform3f(backId, back.X, back.Y, back.Z);
            Gl.glUniform3f(frontId, front.X, front.Y, front.Z);
            Gl.glUniform3f(referenceId, reference.X, reference.Y, reference.Z);

            Gl.glUniform1f(minAxis, cuttingParametres[0].Minimum);
            Gl.glUniform1f(maxAxis, cuttingParametres[0].Maximum);

            Gl.glUniform1f(minAngle, cuttingParametres[1].Minimum);
            Gl.glUniform1f(maxAngle, cuttingParametres[1].Maximum);

            return true;
        }
    }
}
